package com.mxpio.erp.common.workshop.entity;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.jpa.model.Order;
import com.mxpio.erp.common.technology.entity.WorkCenter;
import com.mxpio.erp.common.technology.entity.WorkShop;
import com.mxpioframework.security.annotation.Dict;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_WORKSHOP_MO")
@Schema(description="生产订单")
public class ManufactureOrder extends Order {

	private static final long serialVersionUID = 1L;

	@Column(name = "PRODUCT_ITEM_CODE_")
	@Schema(description = "产品编号")
	private String productItemCode;
	
	@Column(name = "PRODUCT_ITEM_NAME_")
	@Schema(description = "产品名称")
	private String productItemName;
	
	@Column(name = "ITEM_SPEC_")
	@Schema(description = "规格型号")
	private String itemSpec;

	@Column(name = "ORDER_QANTITY_")
	@Schema(description = "订单数量")
	private BigDecimal orderQuantity;
	
	@Column(name = "UNIT_CODE_")
    @Schema(description = "单位编号")
	@Dict(dicCode="ERP_TECH_UNIT_CODE")
    private String unitCode;

	@Column(name = "MAIN_WORKSHOP_")
	@Schema(description = "主制车间")
	@Dict(dicCode = "workShopCode",dicEntity = WorkShop.class,dicText = "workShopName")
	private String mainWorkshop;
	
	@Column(name = "WORK_CENTER_CODE_")
	@Schema(description = "工作中心")
	@Dict(dicCode = "workCenterCode",dicEntity = WorkCenter.class,dicText = "workCenterName")
	private String workCenterCode;

	@Column(name = "PROCESS_ROUTE_")
	@Schema(description = "工艺路线")
	private String processRoute;

	@Column(name = "REFERENCE_DATE_")
	@Schema(description = "参考日期")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date referenceDate;

	@Column(name = "START_DATE_")
	@Schema(description = "计划开始日期")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date startDate;

	@Column(name = "PLANNER_")
	@Schema(description = "计划员")
	private String planner;
	
	@Column(name = "END_DATE")
	@Schema(description = "计划完成日期")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date endDate;
	
	@Column(name = "MEMO_")
	@Schema(description = "备注")
	private String memo;

	@Column(name = "PRODUCT_DRAWING_NO_")
	@Schema(description = "图号")
	private String productDrawingNo;

	@Column(name = "ACTUAL_BEGIN_DATE")
	@Schema(description = "实际开工日期")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date actualBeginDate;

	@Column(name = "ACTUAL_FINISH_DATE")
	@Schema(description = "实际完工日期")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date actualFinishDate;

	/*@Column(name = "ORDER_CLASS_")
	@Schema(description = "单据分类")
	@Dict(dicCode="ERP_WORKSHOP_ORDER_CLASS")//正常1/返工2
	private String orderClass;*/

	@Column(name = "ORDER_TYPE_")
	@Schema(description = "单据类型")//01 普通，02 计划，03 返工
	@Dict(dicCode="ERP_MO_ORDER_TYPE")
	private String orderType;

	@Transient
	private List<ManufactureOrderItem> manufactureOrderItems;
	@Transient
	private List<ManufactureOrderRoute> manufactureOrderRoutes;

	@Override
	public String initTypeCode() {
		return "MO1";
	}

	@Column(name = "ANALYSIS_COLOR_")
	@Schema(description = "齐套分析结果颜色")
	private String analysisColor;

	@Column(name = "ANALYSIS_DATE_")
	@Schema(description = "齐套分析时间")
	private Date analysisDate;

	@Column(name = "KITTING_QUANTITY_")
	@Schema(description = "齐套分析配套数量")
	private BigDecimal kittingQuantity;

	@Transient
	@Schema(description = "已下发数量")
	private BigDecimal preInvestNum;//订单下发数量合计（mes模块）

	@Dict(dicCode = "ERP_COMMON_YESNO")
	@Column(name = "SN_CONTROL_NEEDED")
	@Schema(description = "sn管控")//MES订单下发使用
	private String snControlNeeded;
}
